package com.time.timespace.controller;

import com.time.timespace.commons.dto.ResponseEntity;
import com.time.timespace.domain.dto.TokenDTO;
import com.time.timespace.domain.entity.User;
import com.time.timespace.service.LoginService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/oauth")
public class LoginController {

    @Autowired
    private LoginService loginService;

    @Operation(description = "登录接口")
    @PostMapping("/login")
    public TokenDTO login(@RequestBody User user) {
        return loginService.login(user);
    }

    @Operation(description = "注销")
    @PostMapping("/logout")
    public ResponseEntity<?> logout(HttpServletRequest request){
        return loginService.logout(request);
    }

    @Operation(description = "获取当前用户身份信息-Name")
    @GetMapping("/self/name")
    public User getSelfByName(String userName) {
        return loginService.getSelfByName(userName);
    }

    @Operation(description = "获取当前用户身份信息")
    @GetMapping("/self/{userId}")
    public User getSelfInfo(@PathVariable Long userId) {
        return loginService.getSelfInfo(userId);
    }

    @Operation(description = "修改用户信息")
    @PostMapping("/self/update")
    public void selfUpdate(@RequestBody User user) {
        loginService.selfUpdate(user);
    }
}
